<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<head>

</head>
<body>
	<div class="x-nav">
		<div class="select" >
			<span class="layui-breadcrumb" style="padding-top: 5px;display: inline-block;">
			  <a href="javascript:void(0)">首页</a><a href="javascript:void(0)">系统管理</a><a><cite>权限管理</cite></a>
			</span>
			<button class="layui-btn layui-btn-sm" id="refresh" style="float: right;" data-type="reload"><i class="layui-icon">ဂ</i></button>
		</div>
	</div>
	<div class="layui-col-md12" style="height:40px;margin-top:3px;">
		<form class="layui-form" action="javaScript:void(0);" id="indexSerchForm">
			名称:<div class="layui-inline">
				<input class="layui-input" height="20px" id="name" autocomplete="off">
			</div>
			<div class="layui-btn-group" style="float: right;margin-right: 20px;">
				<button class="select-on layui-btn layui-btn-sm" data-type="select"><i class="layui-icon"></i></button>
				<button class="select-on layui-btn layui-btn-sm" data-type="reload"><i class="layui-icon">&#x1007;</i>重置</button>
				<button class="select-on layui-btn layui-btn-sm" data-type="add"><i class="layui-icon">&#xe608;</i>新增</button>
				<%--<button class="select-on layui-btn layui-btn-sm" data-type="dels"><i class="layui-icon">&#xe640;</i>删除</button>--%>
			</div>
		</form>
	</div>
	<table id="pageList" class="layui-hide" lay-filter="user"></table>
	<script type="text/html" id="barDemo">
		{{# if(!d.isSysRole){ }}
			<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
			<a class="layui-btn layui-btn-xs  layui-btn-normal" lay-event="edit">编辑</a>
			<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" id="delBtn">删除</a>
		{{# } }}
	</script>
</body>
<myfooter>
	<script>
		function reload(table) {
            table.reload('pageList', {
                where: {
                    search_LIKE_name: $("#name").val(),
                }
            });
        }

        var layerOpenH = "400";
        var layerOpenW = "700";
        var queryUrl = "${ctx}/role/queryByPage";
        var delUrl = "${ctx}/role/deleteEntity";
		var saveUrl = "${ctx}/role/findOne";

        layui.use('table', function () {
            var table = layui.table;
            //方法级渲染
            table.render({
                id: 'pageList',
                elem: '#pageList',//指定原始表格元素选择器（推荐id选择器）
                url: queryUrl,
                cols: [[
                    {type:"numbers",fixed: true, width: '5%'},
                    {field: 'name',title: '名称',width: '20%'},
                    {field: 'code', title: 'code', width: '30%'},
                    {field: 'createDate', title: '创建时间', width: '25%',sort: true},
                    {field: 'right', title: '操作', width: '20%', toolbar: "#barDemo"}
                ]],
                page: true,
                height: 'full-105'
            });
            var $ = layui.$,
			active = {
                select: function () {
                    reload(table);
                },
                reload:function(){
					$("#indexSerchForm").find('input').val("");
                    $("#indexSerchForm").find('select').val("");
                    reload(table);
                },
                add: function () {
                    layerSave('添加', saveUrl+"?1=1", layerOpenW, layerOpenH);
                }
			};
            //监听工具条
            table.on('tool(user)', function (obj) {
                var data = obj.data;
                if (obj.event === 'detail') {
                    layerDetail('查看', saveUrl+'?id=' + data.id, layerOpenW, layerOpenH);
                } else if (obj.event === 'del') {
                    layer.confirm('确定删除[<label style="color: #00AA91;">' + data.name + '</label>]?',function (index) {
                        layerDel(delUrl,data.id, true);
                        reload(table);
                        layer.close(index);
                    });

                } else if (obj.event === 'edit') {
                    layerSave('编辑', saveUrl+'?id=' + data.id, layerOpenW, layerOpenH);
                }
            });
            /*头部按钮和刷新按钮的点击触发*/
            $('.layui-col-md12 .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            $('.select .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });
	</script>
</myfooter>
